﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace SerialPort_Assistant.Command
{
    public class BaseCommand : ICommand
    {
        public event EventHandler? CanExecuteChanged;

        private readonly Action<object> ExecuteAction;
        private readonly Func<object, bool> CanExecuteAction;

        public BaseCommand(Action<object> executeAction, Func<object, bool> canExecuteAction)
        {
            ExecuteAction = executeAction;
            CanExecuteAction = canExecuteAction;
        }

        public bool CanExecute(object? parameter)
        {
            return CanExecuteAction == null || CanExecuteAction(parameter);
        }

        public void Execute(object? parameter)
        {
            ExecuteAction?.Invoke(parameter);
        }
    }
}
